package cn.vehicle.service.impl;


import cn.vehicle.domains.entity.SysUserEntity;
import cn.vehicle.mapper.SysUserMapper;
import cn.vehicle.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 新增用户
     *
     * @param sysUserEntity 用户实体对象
     */
    @Override
    public void addUser(SysUserEntity sysUserEntity) {
        try {
            sysUserMapper.insertUser(sysUserEntity);
        } catch (DuplicateKeyException e) {
            //throw VehicleAccessException.DATE_EXIST.newInstance("用户已存在");
        }
    }

    /**
     * 根据ID查询用户
     *
     * @param id 用户ID
     * @return 用户实体对象
     */
    @Override
    public SysUserEntity getUserById(Long id) {
        return sysUserMapper.selectUserById(id);
    }

    @Override
    public void updateUser(SysUserEntity updateEntity) {
        int i = sysUserMapper.updateUser(updateEntity);
        if (i != 1) {
            //throw VehicleAccessException.DATE_NOT_EXIST.newInstance("更新用户未更新到数据");
        }
    }

}
